<h1>Listing Test Logs</h1>

Number of Logs: <%= @test_logs.count %>
</br>
Below 60 min: <%= number_to_percentage(@below_60_percent, precision: 2) %>
</br>

<table class="box-table">
	<thead>
	  <tr>
	    <th>Test Execution Date</th>
	    <th>Algorithm Name</th>
	    <th>Algorithm Version</th>
	    <th>Device Model</th>
	    <th>SO Version</th>
	    <th>Forecast Horizon</th>
	    <th>Duration (ms)</th>
	    <th>Memory Used (kb)</th>
	    <th>Energy Used (J)</th>
	    <th>MAE (min)</th>
	    <th>MAPE (min)</th>
	    <th>Base Data Type</th>
	    <th>Used Threshold</th>
	    <th>Used Days Ago</th>
	  </tr>
  </thead>
<% if !@test_logs.empty? %>
	<% i = 1 %>
	<% while i <= params[:forecast_horizon].to_i do %>
		<tr>
			<td><%= @test_logs.first.executed_at-3.hours %></td>
			<td><%= params[:algorithm_name] %></td>
			<td><%= params[:algorithm_version] %></td>
			<td><%= @test_logs.first.device_model %></td>
			<td><%= @test_logs.first.SO_version %></td>
			<td><%= i %></td>
			<td><%= TestLog.calc_duration_average @test_logs %></td>
			<td><%= number_with_precision(TestLog.calc_mem_use_average(@test_logs)/1024, precision: 2) %></td>
			<td><%= number_with_precision(TestLog.calc_energy_use_average(@test_logs), precision: 2) %></td>
			<td><%= number_with_precision(TestLog.calc_mae_average(@test_logs, i), precision: 2) %></td>
			<td><%= number_to_percentage(TestLog.calc_mape_average(@test_logs), precision: 2) %></td>
			<td><%= params[:base_data_type] %></td>
			<td><%= @test_logs.first.test_base_data.used_threshold %></td>
			<td><%= @test_logs.first.test_base_data.used_days_ago %></td>
		</tr>
		<% i+=1 %>
	<% end %>
<% end %>
</table>

<table id="sortable-list" class="box-table">
  <thead>
	  <tr>
	  	<th scope="col">Opções</th>
	    <th scope="col">Test Execution Date</th>
	    <th data-sort="string" scope="col">Algorithm Name</th>
	    <th data-sort="int" scope="col">Algorithm Version</th>
	    <th data-sort="string" scope="col">Device Model</th>
	    <th data-sort="int" scope="col">SO Version</th>
	    <th data-sort="int" scope="col">Forecast Horizon</th>
	    <th data-sort="int" scope="col">Duration (ms)</th>
	    <th data-sort="int" scope="col">Memory Used (kb)</th>
	    <th data-sort="int" scope="col">Energy Used (J)</th>
	    <th data-sort="int" scope="col">MAE (min)</th>
	    <th data-sort="int" scope="col">MAPE (min)</th>
	    
	    			<!-- Test Base Data -->
	    <th scope="col">Base Data Created At</th>
	    <th data-sort="string" scope="col">Base Data Type</th>
	    <th data-sort="string" scope="col">UserUUID</th>
	    <th data-sort="int" scope="col">Used Threshold</th>
	    <th data-sort="int" scope="col">Used Days Ago</th>
	    <th data-sort="int" scope="col">Base Data Points</th>
	  </tr>
  </thead>

	<tbody>
	<% @test_logs.each do |test_log| %>
		<tr>
			<td><a href="<%= test_log_show_path %>?test_log_id=<%= test_log.id %>"> Exibir Detalhes </a> <a href="<%= test_log_delete_path %>?test_log_id=<%= test_log.id %>"> Deletar </a></td>
			<td><%= test_log.executed_at-3.hours %></td>
			<td><%= test_log.algorithm_name %></td>
			<td><%= test_log.algorithm_version %></td>
			<td><%= test_log.device_model %></td>
			<td><%= test_log.SO_version %></td>
			<td><%= test_log.forecast_horizon %></td>
			<td><%= test_log.duration %></td>
			<td><%= number_with_precision(test_log.memory_used/1024, precision: 2) %></td>
			<td><%= number_with_precision(test_log.energy_used, precision: 2) %></td>
			<td><%= number_with_precision(TestLog.get_mean_absolute_error(test_log, test_log.forecast_horizon), precision: 2) %></td>
			<td><%= number_with_precision(TestLog.get_mean_absolute_percentage_error(test_log), precision: 2) %></td>
			<td><%= test_log.test_base_data.base_data_created_at-3.hours %></td>
			<td><%= test_log.test_base_data.base_data_type %></td>
			<td><%= test_log.test_base_data.user_uuid %></td>
			<td><%= test_log.test_base_data.used_threshold %></td>
			<td><%= test_log.test_base_data.used_days_ago %></td>
			<td><%= Marshal.load(test_log.test_base_data.base_data).count %></td>
		</tr>
	<% end %>
	</tbody>
</table>

